package com.doumi.biz.qadev.api.testcase.commonfilter;

import com.doumi.biz.qadev.api.methods.OperationRedis;
import com.doumi.biz.qadev.api.testcase.RequestTemplate;
import io.restassured.path.json.JsonPath;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by YDZ on 2019/11/30.
 */
public class CommonFilterCompanyUnmask {

    /**
     * 被十家企业举报
     */
    private RequestTemplate requestTemplate = new RequestTemplate();
    private OperationRedis operationRedis = new OperationRedis();
    private static List<String> cuIds = new ArrayList<>();
    HashMap hashMap = new HashMap();
    String rediskey = "wt_company_unmask";

    //redis初始化数据
    @BeforeClass(description = "初始化redis数据")
    public  void operationData(){
        String filenanme = "src/source/redisfile/filter-companyunmask.csv";
        String mothodname = "businessbehavior";
        cuIds = operationRedis.readCsvoperationRedis(filenanme,mothodname,4);
        hashMap.put("companyId","11111");
        hashMap.put("buserId",321245);
        operationRedis.operationRedisSet(rediskey,cuIds.get(0),cuIds.get(1),cuIds.get(2));
    }
    @Test(description = "用户被十家企业举报过，242211104用户没有被举报过，预期结果返回该用户")
    public void checkCompanyUnmask(){
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i <cuIds.size()-1;  i++) {
            sb.append(cuIds.get(i).trim()).append(",");
        }
        sb.append(cuIds.get(cuIds.size()-1).trim());
        sb.append("]");
        hashMap.put("cuIds",sb.toString());
        hashMap.put("businessType","1");
        hashMap.put("contactStatus",1);

        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String msg = jsonPath.getString("msg");
        Assert.assertEquals(resurlt.size(),1);
        Assert.assertEquals(msg,"success");
    }
    @Test(description = "用户被十家企业举报过，242211104用户没有被举报过，但是action为1不走当前过滤，预期结果返回所有用户")
    public void checkCompanyUnmaskNotAction(){
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i <cuIds.size()-1;  i++) {
            sb.append(cuIds.get(i).trim()).append(",");
        }
        sb.append(cuIds.get(cuIds.size()-1).trim());
        sb.append("]");
        hashMap.put("cuIds",sb.toString());
        hashMap.put("businessType","1");
        hashMap.put("contactStatus",1);
        hashMap.put("actions","1");
        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String msg = jsonPath.getString("msg");
        Assert.assertEquals(resurlt.size(),4);
        Assert.assertEquals(msg,"success");
    }
    @Test(description = "用户被十家企业举报过，242211109用户没有基本信息，但是过滤条件action为6和用户信息没有关系，该用户应该返回")
    public void checkCompanyUnmaskNotActionAndNotUserBaseInfo(){

        hashMap.put("cuIds","242211109");
        hashMap.put("businessType","1");
        hashMap.put("contactStatus",1);
        hashMap.put("actions","6");
        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String msg = jsonPath.getString("msg");
        Assert.assertEquals(resurlt.size(),1);
        Assert.assertEquals(msg,"success");
    }
    //删除数据
    @AfterClass(description = "删除出入掉的数据，避免影响其他测试")
    public void removeData(){
        operationRedis.removeRedis(cuIds);
//        operationRedis.removeRedis(rediskey);
//        operationRedis.clearRedisCallTimes();//清空特殊的值
//      String s=  operationRedis.getValue();
//        System.out.println(s);

    }

}
